package springapp.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import springapp.entity.SalaryEntity;

@Repository
public class SalaryDao extends HibernateDao<SalaryEntity, Integer> {

	public static final String[] COLUMNS = new String[] { "gender", "salary",
			"experience", "jobType" };

	@SuppressWarnings("unchecked")
	public List<SalaryEntity> getSalariesForCompanyId(Integer companyId) {
		Map<String, Object> searhMap = new HashMap<String, Object>();
		searhMap.put("companyEntity.companyId", companyId);
		List<Object[]> list = executeSqlQuery(COLUMNS, "SalaryEntity", searhMap);
		List<SalaryEntity> salaryEntities = new ArrayList<SalaryEntity>();
		for (Object[] objects : list) {
			SalaryEntity salaryEntity = new SalaryEntity();
			salaryEntity.setGender((String) objects[0]);
			salaryEntity.setSalary((Float) objects[1]);
			salaryEntity.setExperience((Integer) objects[2]);
			salaryEntity.setJobType((String) objects[3]);
			salaryEntities.add(salaryEntity);
		}
		return salaryEntities;
	}
	
	@SuppressWarnings("rawtypes")
	public int getNumSalariesForCompany(Integer companyId){
		String sql = "select count(*) from SalaryEntity where companyEntity.companyId="+companyId;
		List list = executeAggregateQuery(sql);
		return (Integer) list.get(0);
	}
}
